package com.klw.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.klw.common.annotation.Log;
import com.klw.common.core.controller.BaseController;
import com.klw.common.core.domain.AjaxResult;
import com.klw.common.enums.BusinessType;
import com.klw.business.domain.KlwStudentAttendance;
import com.klw.business.service.IKlwStudentAttendanceService;
import com.klw.common.utils.poi.ExcelUtil;
import com.klw.common.core.page.TableDataInfo;

/**
 * 学生出勤记录Controller
 * 
 * @author klw
 * @date 2025-08-24
 */
@RestController
@RequestMapping("/core/attendance")
public class KlwStudentAttendanceController extends BaseController
{
    @Autowired
    private IKlwStudentAttendanceService klwStudentAttendanceService;

    /**
     * 查询学生出勤记录列表
     */
    @PreAuthorize("@ss.hasPermi('core:attendance:list')")
    @GetMapping("/list")
    public TableDataInfo list(KlwStudentAttendance klwStudentAttendance)
    {
        startPage();
        List<KlwStudentAttendance> list = klwStudentAttendanceService.selectKlwStudentAttendanceList(klwStudentAttendance);
        return getDataTable(list);
    }

    /**
     * 导出学生出勤记录列表
     */
    @PreAuthorize("@ss.hasPermi('core:attendance:export')")
    @Log(title = "学生出勤记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KlwStudentAttendance klwStudentAttendance)
    {
        List<KlwStudentAttendance> list = klwStudentAttendanceService.selectKlwStudentAttendanceList(klwStudentAttendance);
        ExcelUtil<KlwStudentAttendance> util = new ExcelUtil<KlwStudentAttendance>(KlwStudentAttendance.class);
        util.exportExcel(response, list, "学生出勤记录数据");
    }

    /**
     * 获取学生出勤记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('core:attendance:query')")
    @GetMapping(value = "/{attendanceId}")
    public AjaxResult getInfo(@PathVariable("attendanceId") Long attendanceId)
    {
        return success(klwStudentAttendanceService.selectKlwStudentAttendanceByAttendanceId(attendanceId));
    }

    /**
     * 新增学生出勤记录
     */
    @PreAuthorize("@ss.hasPermi('core:attendance:add')")
    @Log(title = "学生出勤记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KlwStudentAttendance klwStudentAttendance)
    {
        return toAjax(klwStudentAttendanceService.insertKlwStudentAttendance(klwStudentAttendance));
    }

    /**
     * 修改学生出勤记录
     */
    @PreAuthorize("@ss.hasPermi('core:attendance:edit')")
    @Log(title = "学生出勤记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KlwStudentAttendance klwStudentAttendance)
    {
        return toAjax(klwStudentAttendanceService.updateKlwStudentAttendance(klwStudentAttendance));
    }

    /**
     * 删除学生出勤记录
     */
    @PreAuthorize("@ss.hasPermi('core:attendance:remove')")
    @Log(title = "学生出勤记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attendanceIds}")
    public AjaxResult remove(@PathVariable Long[] attendanceIds)
    {
        return toAjax(klwStudentAttendanceService.deleteKlwStudentAttendanceByAttendanceIds(attendanceIds));
    }
}
